/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ChoixNombreDeLots.java
 *
 * Created on 23 juin 2009, 01:05:55
 */

package caylus.GUI;

/**
 *
 * @author CeZar
 */
public class ChoixNombreDeLots extends javax.swing.JDialog {
    private int _nbLots = 1;
    private PlateauDuJeu papa ;

    /** Creates new form ChoixNombreDeLots */
    public ChoixNombreDeLots(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        papa = (PlateauDuJeu) parent ;
        centrerFenetre();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabelOK = new javax.swing.JLabel();
        jSpinnerNbLots = new javax.swing.JSpinner();
        jLabelInformation = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Phase 6 : Nombre de lots");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Nombre de lots"));

        jLabelOK.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/caylus_button_ok.png"))); // NOI18N
        jLabelOK.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabelOKMouseClicked(evt);
            }
        });

        jSpinnerNbLots.setModel(new javax.swing.SpinnerNumberModel(1, 0, 3, 1));
        jSpinnerNbLots.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinnerNbLotsStateChanged(evt);
            }
        });

        jLabelInformation.setForeground(new java.awt.Color(0, 51, 51));
        jLabelInformation.setText("Combien de lots vous comptez fournir ?");

        jLabel1.setForeground(new java.awt.Color(0, 153, 0));
        jLabel1.setText("J'en fourni");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jLabelInformation)
                        .addGap(52, 52, 52))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(jSpinnerNbLots, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(85, 85, 85)))
                .addComponent(jLabelOK)
                .addGap(30, 30, 30))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabelInformation)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jSpinnerNbLots, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1)))
                    .addComponent(jLabelOK, javax.swing.GroupLayout.Alignment.LEADING))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 369, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jLabelOKMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelOKMouseClicked
            if(jLabelOK.isEnabled()){
                papa.nbLots = _nbLots;
                dispose();
            }   
}//GEN-LAST:event_jLabelOKMouseClicked

    private void jSpinnerNbLotsStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinnerNbLotsStateChanged
            _nbLots = (Integer) jSpinnerNbLots.getModel().getValue();
            if(_nbLots == 0)
                jLabelOK.setEnabled(false);
            else
                jLabelOK.setEnabled(true);
}//GEN-LAST:event_jSpinnerNbLotsStateChanged


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelInformation;
    private javax.swing.JLabel jLabelOK;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSpinner jSpinnerNbLots;
    // End of variables declaration//GEN-END:variables

    public void centrerFenetre(){
            java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
            pack();
            setLocation(
                        (screenSize.width-this.getWidth())/2,
                        (screenSize.height-this.getHeight())/2
                       );
    }
}
